
import store from '@/store'
import Vue from 'vue'
import VueRouter from 'vue-router'
import HomeView from '../views/HomeView.vue'

Vue.use(VueRouter)

const routes = [
  {
    path:'/',
    redirect:'/home/index'  // 重定向
  },
  {
    path: '/home',
    name: 'home',
    component: HomeView,
    children:[
      {
        path:'index',
        component: () => import(/* webpackChunkName: "about" */ '../views/Index.vue'),
        meta: {
          thumb: ['首页']
        }
      },
      {
        path:'actor-list',
        component: () => import(/* webpackChunkName: "about" */ '../views/actor/ActorList.vue'),
        // 在此处配置meta的作用意味着希望为该路由对象绑定着一些自定义数据
       // 这些自定数据在组件间可以直接访问：
       // 通过this.$routr.meta.thumb 访问数组
        meta:{
          thumb:['演员管理','演员列表']
        }
      },
      {
        path:'actor-add',
        component: () => import(/* webpackChunkName: "about" */ '../views/actor/ActorAdd.vue'),
        meta:{
          thumb: ['演员管理', '新增演员']
        }
      },
      
      {
        path:'director-list',
        component: () => import(/* webpackChunkName: "about" */ '../views/director/DirectorList.vue'),
        meta:{
          thumb: ['导演管理', '导演列表']
        }
      },
      {
        path:'director-add',
        component: () => import(/* webpackChunkName: "about" */ '../views/director/DirectorAdd.vue'),
        meta:{
          thumb: ['导演管理', '新增导演']
        }
      },
      {
        path: 'movie-list',
        component: () => import('../views/movie/MovieList.vue'),
        meta:{
          thumb: ['电影管理', '电影列表']
        }
      },
      {
        path: 'movie-add',
        component: () => import('../views/movie/MovieAdd.vue'),
        meta:{
          thumb: ['电影管理', '新增电影']
        }
      },
      {
        path: 'movie-update/:id',
        component: () => import('../views/movie/MovieUpdate.vue'),
        meta:{
          thumb: ['电影管理', '电影列表', '修改电影']
        }
      },
      {
        path: 'cinema-add',
        component: () => import('../views/cinema/CinemaAdd.vue'),
        meta:{
          thumb: ['电影院管理', '添加电影院']
        }
      },
      {
        path: 'cinema-List',
        component: () => import('../views/cinema/CinemaList.vue'),
        meta:{
          thumb: ['电影院管理', '电影院列表']
           // thumb: [{text:'电影管理', to:'/home/movie-list'}, {text:'电影列表', to:'/home/movie-list'}]
        }
      },
      {
        path: 'cinema-room-List/:cinemaId',
        component: () => import('../views/cinema/CinemaRoomList.vue'),
        meta:{
          thumb: ['电影院管理', '电影院列表','放映厅列表']
           // thumb: [{text:'电影管理', to:'/home/movie-list'}, {text:'电影列表', to:'/home/movie-list'}]
        }
      },
      {
        path: 'showingon-plan-add/:roomId',
        component: () => import('../views/cinema/ShowingonPlanAdd.vue'),
        meta:{
          thumb: ['电影院管理', '电影院列表','放映厅列表']
           // thumb: [{text:'电影管理', to:'/home/movie-list'}, {text:'电影列表', to:'/home/movie-list'}]
        }
      },
      {
        path: 'showingon-plan-list/:roomId',
        component: () => import('../views/cinema/ShowingonPlanList.vue'),
        meta:{
          thumb: ['电影院管理', '电影院列表','放映厅排片计划列表']
           // thumb: [{text:'电影管理', to:'/home/movie-list'}, {text:'电影列表', to:'/home/movie-list'}]
        }
      },
      {
        path: 'seat-template/:roomId',
        component: () => import('../views/cinema/CinemaRoomSeatTemplate.vue'),
        meta:{
          thumb: ['电影院管理', '电影院列表','放映厅列表','配置座位模板']
           // thumb: [{text:'电影管理', to:'/home/movie-list'}, {text:'电影列表', to:'/home/movie-list'}]
        }
      },
    ]
  },
  {
    path: '/user/login',
    name: 'login',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import(/* webpackChunkName: "about" */ '../views/user/Login.vue')
  }
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

// 添加守卫
router.beforeEach((to,from,next)=>{
  // console.log(from)
  console.log(to)
  if(to.path=='/user/login' || store.state.user){
    next()
  }else{
    router.push('/user/login')
  }
  
})

export default router
